#include "Intersections.h"

namespace Geometry
{
	bool intersection( Ray _r , Plane _p , Point& _inter )
	{
		double n_dot_d = _p.n() * _r.q();
		double neg_n_dot_o_minus_q = -_p.n() * ( _r.p() - _p.p() );

		if( n_dot_d != 0 )
		{
			double t = neg_n_dot_o_minus_q / n_dot_d;
			_inter = ( t * _r.q() ) + _r.p();
			return true;

		}
		else if( neg_n_dot_o_minus_q == 0  &&  n_dot_d == 0 )
		{
			_inter = _r.p();
			return true;
		}
		else
		{
			return false;
		}
	}
}